<?php
    /**
     * Created by PhpStorm.
     * User: timeteam
     * Date: 19-1-3
     * Time: 下午3:47
     */

    namespace util;

    use app\autotask\queue\work\SystemLog;
    use think\App;
    use think\facade\Request;

    class Logger
    {
        protected $config = [];

        // 实例化并传入参数
        public function __construct(App $app, $config = [])
        {
            $this->config = array_merge($this->config, $config);

        }

        /**
         * 日志写入接口
         * @access public
         * @param  array $log 日志信息
         * @param  bool $append 是否追加请求信息
         * @return bool
         */
        public function save(array $log = [], $append = false)
        {
            if ($append) {
                $log['Request']['header']   = Request::header();
                $log['Request']['param']    = Request::param();
                $log['Request']['pathinfo'] = Request::pathinfo();
            }
             file_put_contents(env('runtime_path') . 'log/test_' . date('Y-m-d', time()) . '.log', json_encode($log) . PHP_EOL, FILE_APPEND);
        }
    }